package com.alix.paymoney.presenter.impl;

import com.alix.paymoney.entity.BaseBean;
import com.alix.paymoney.http.CallManager;
import com.alix.paymoney.http.HttpManager;
import com.alix.paymoney.http.OnResponseListener;
import com.alix.paymoney.http.request.CodeRequest;
import com.alix.paymoney.presenter.CodePresenter;
import com.alix.paymoney.utils.Loger;
import com.alix.paymoney.view.CodeView;

import retrofit2.Call;

/**
 * Created by wushiqian on 2017/11/13.
 */

public class CodePresenterImpl extends BasePresenterImpl<CodeView> implements CodePresenter {
    public CodePresenterImpl(CodeView codeView) {
        super(codeView);
    }

    @Override
    public void getCode(String telephone) {
        CodeRequest codeRequest = new CodeRequest();
        codeRequest.setTelphone(telephone);
        Call<BaseBean> code = HttpManager.getInstance().getApiService().getCode(telephone);
        CallManager.getInstance().addQueue(code, new OnResponseListener<BaseBean>() {
            @Override
            public void Success(BaseBean o) {
                getView().getCodeSuccess();

            }

            @Override
            public void onFailed(int errorCode, String errorInfo) {
                getView().getCodeError(errorCode, errorInfo);
                Loger.e(errorInfo+"获取验证码"+errorCode);
            }

            @Override
            public void onException(String msg) {
                getView().showTips(msg);
            }


        });
    }


}
